<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>有没有两数之和</title>
</head>

<body>
  <script>
    function sums(arr, num) {
      let differ = {};
      for (let i = 0; i < arr.length; i++) {
        let sub = num - arr[i];
        if (differ[sub]) {
          return true;
        }
        else {
          differ[arr[i]] = true;
        }
      }
      return false;
    }
    console.log(sums([6, 4, 3, 2, 1, 7], 8));
  </script>
</body>

</html>